<?php
// +----------------------------------------------------------------------
// | ManniuRead
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://manniuyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: heitao <read@manniuyun.com>
// +----------------------------------------------------------------------

namespace app\admin\model;

use manniu\model\Base;

use app\admin\model\Linkage;

class LinkageData extends Base
{
    /**
     * 树形结构 - array
     * @access public
     * @param int $pid  父栏目ID
     * @return array
     */
    public function getTreeArray($pid = 0, $linkage_id = 0) {
        $pid = (int)$pid;
        $linkage_id = (int)$linkage_id;
        // 查询所有内容
        $result = $this->order(['display_order'=> 'asc','id'=>'asc','linkage_id'=>$linkage_id])->select();
        // 实例化树型类
        $tree = new \manniu\tools\Tree;
        //设置树型结构所需的数组
        $tree->init(collection($result)->toArray());
        $data = $tree->getTreeArray($pid);
        return $data ? $data : [];
    }
}